package com.ruoyi.jl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.jl.domain.GiveGold;
import com.ruoyi.jl.mapper.GiveGoldMapper;
import com.ruoyi.jl.service.IGiveGoldService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 赠送金币 服务层实现
 *
 * @author wh
 * @date 2019-04-29
 */
@Slf4j
@Service
public class GiveGoldServiceImpl extends ServiceImpl<GiveGoldMapper, GiveGold> implements IGiveGoldService {

    @Autowired
    GiveGoldMapper giveGoldMapper;

    @Override
    public List<GiveGold> list(GiveGold giveGold) {
        QueryWrapper wrapper = new QueryWrapper();
        // LambdaQueryWrapper<GiveGold> wrapper = new LambdaQueryWrapper<>();
        if (giveGold != null) {
            if (StringUtils.isNotEmpty(giveGold.getId())) {
                wrapper.eq("id", giveGold.getId());
            }
            if (StringUtils.isNotEmpty(giveGold.getGiveId())) {
                wrapper.eq("give_id", giveGold.getGiveId());
            }
            if (StringUtils.isNotEmpty(giveGold.getReceiveId())) {
                wrapper.eq("receive_id", giveGold.getReceiveId());
            }
            if (StringUtils.isNotEmpty(giveGold.getGoldNum())) {
                wrapper.eq("gold_num", giveGold.getGoldNum());
            }
            if (StringUtils.isNotEmpty(giveGold.getIpAddress())) {
                wrapper.eq("ip_address", giveGold.getIpAddress());
            }

            if (StringUtils.isNotEmpty(giveGold.getParams().get("beginTime"))) {
                wrapper.ge("give_time", giveGold.getParams().get("beginTime"));
            }
            if (StringUtils.isNotEmpty(giveGold.getParams().get("endTime"))) {
                wrapper.le("give_time", giveGold.getParams().get("endTime"));
            }
        }
        return baseMapper.selectList(wrapper);
    }

    /**
     * 查询玩家赠送金币列表
     *
     * @param playerId
     * @return
     */
    @Override
    public List<GiveGold> queryGiveLog(Integer playerId) {
        List<GiveGold> list = giveGoldMapper.queryGiveLog(playerId);
        return list;
    }
}
